package com.mashibing.servicedriveruser.controller;

import com.mashibing.internalcommon.constant.DriverCarConstants;
import com.mashibing.internalcommon.dto.DriverCarBindingRelationship;
import com.mashibing.internalcommon.dto.DriverUser;
import com.mashibing.internalcommon.dto.DriverUserWorkStatus;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.response.DriverUserExistsResponse;
import com.mashibing.internalcommon.response.OrderDriverResponse;
import com.mashibing.servicedriveruser.mapper.DriverUserWorkStatusMapper;
import com.mashibing.servicedriveruser.service.DriverCarBindingRelationshipService;
import com.mashibing.servicedriveruser.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Driver;
import java.time.LocalDateTime;

/**
 * @author 史慕尧
 */
@RestController
public class UserController {
    @Autowired
    UserService userService;


    @PostMapping("/user")
    public ResponseResult addUser(@RequestBody DriverUser driverUser) {

        return userService.addUser(driverUser);
    }

@PutMapping("/user")
    public  ResponseResult updateUser(@RequestBody DriverUser driverUser){
        return userService.updateUser(driverUser);
}

@GetMapping("/check-driver/{driverPhone}")
    public ResponseResult<DriverUser> getUser(@PathVariable("driverPhone") String driverPhone){
    ResponseResult<DriverUser> driverUserByPhone = userService.getDriverUserByPhone(driverPhone);
    DriverUser driverUserDB = driverUserByPhone.getData();
    DriverUserExistsResponse driverUserExistsResponse = new DriverUserExistsResponse();
    int ifExists= DriverCarConstants.DRIVER_EXISTS;
    if (driverUserDB==null){
        ifExists=DriverCarConstants.DRIVER_NOT_EXISTS;
        driverUserExistsResponse.setIfExists(ifExists);
        driverUserExistsResponse.setDriverPhone(driverPhone);
    }else {
        driverUserExistsResponse.setIfExists(ifExists);
        driverUserExistsResponse.setDriverPhone(driverUserDB.getDriverPhone());
    }

    return ResponseResult.success(driverUserExistsResponse);
}

@GetMapping("/get-available-driver/{carId}")
    public ResponseResult<OrderDriverResponse> getAvailableDriver(@PathVariable("carId") String carId){
return  userService.getAvailableDriver(carId);
}

    @Autowired
    DriverCarBindingRelationshipService driverCarBindingRelationshipService;

    /**
     * 根据司机手机号查询司机和车辆绑定关系
     * @param driverPhone
     * @return
     */
    @GetMapping("/driver-car-binding-relationship")
    public ResponseResult<DriverCarBindingRelationship> getDriverCarRelationShip(@RequestParam String driverPhone){
        return driverCarBindingRelationshipService.getDriverCarRelationShipByDriverPhone(driverPhone);
    }

}
